#coding=utf-8

import sys
from PyQt5.QtWidgets import QWidget, QApplication, QToolButton, QMenu, QAction
from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtGui import QIcon, QDesktopServices

class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.InitUi()
        
    def InitUi(self):
        self.resize(400, 300)
        self.setWindowTitle('工具按钮（QToolButton）')
        
        tb=QToolButton(self)
        tb.move(100, 100)
        tb.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        tb.setPopupMode(QToolButton.InstantPopup)
        tb.setToolTip('选择适合你的支付方式')
        tb.setText('支付方式')
        tb.setIcon(QIcon('icon/bank.ico'))
        tb.setAutoRaise(True)
        
        menu=QMenu(self)
        self.alipayAct=QAction(QIcon('icon/alipay.ico'), '支付宝支付', self)
        self.wechatAct=QAction(QIcon('icon/wechat.ico'), '微信支付', self)
        self.unionpayAct=QAction(QIcon('icon/UnionPay.ico'), '银联支付', self)
        self.visaAct=QAction(QIcon('icon/visa.ico'), 'Visa卡支付', self)
        self.masterAct=QAction(QIcon('icon/master_card.ico'), '万事达卡支付', self)
        self.bitcoinAct=QAction(QIcon('icon/Bitcoin.ico'), '比特币支付', self)
        
        
        menu.addAction(self.alipayAct)
        menu.addAction(self.wechatAct)
        menu.addAction(self.unionpayAct)
        menu.addSeparator()
        menu.addAction(self.visaAct)
        menu.addAction(self.masterAct)
        menu.addSeparator()
        menu.addAction(self.bitcoinAct)
        
        tb.setMenu(menu)
        self.show()
        
        self.alipayAct.triggered.connect(self.on_click)
        self.visaAct.triggered.connect(self.on_click)
        self.wechatAct.triggered.connect(self.on_click)
        self.masterAct.triggered.connect(self.on_click)
        self.unionpayAct.triggered.connect(self.on_click)
        self.bitcoinAct.triggered.connect(self.on_click)
        
    def on_click(self):
        if self.sender()==self.alipayAct:
            QDesktopServices.openUrl(QUrl('https://www.alipay.com/'))
        elif self.sender()==self.wechatAct:
            QDesktopServices.openUrl(QUrl('https://pay.weixin.qq.com/index.php'))
        elif self.sender()==self.visaAct:
            QDesktopServices.openUrl(QUrl('https://www.visa.com.cn/'))
        elif self.sender()==self.unionpayAct:
            QDesktopServices.openUrl(QUrl('http://cn.unionpay.com/'))
        elif self.sender()==self.bitcoinAct:
            QDesktopServices.openUrl(QUrl('https://spectrocoin.com/zh-CN/'))
        else:
            QDesktopServices.openUrl(QUrl('https://www.mastercard.com.cn/zh-cn.html'))
            
if __name__=='__main__':
    app=QApplication(sys.argv)
    ex=Example()
    sys.exit(app.exec_())
